#ifndef _MINI_CRT_H_
#define _MINI_CRT_H_

#ifdef __cplusplus
extern "C"{
#endif

// entry.c
void mini_crt_entry(void);

// malloc.c
#ifndef NULL
#define NULL (0)
#endif

int mini_crt_heap_init();
void mfree(void* ptr);
void* mmalloc(unsigned size);

// stdio.c
typedef int FILE;
#define EOF (-1)
#define stdin	((FILE*)(GetStdHandle(STD_INPUT_HANDLE)))
#define stdout	((FILE*)(GetStdHandle(STD_OUTPUT_HANDLE)))
#define stderr	((FILE*)(GetStdHandle(STD_ERROR_HANDLE)))

int mini_crt_io_init();
FILE* fopen(const char* filename,const char* mode);
int fread(void* buffer,int size,int count,FILE* stream);
int fwrite(const void* buffer,int size,int count,FILE* stream);
int fclose(FILE* fp);
int fseek(FILE* fp,int offset,int set);

// string.c
char* mitoa(int n,char* str,int radix);
int strcmp(const char* src,const char* dst);
char* strcpy(char* dest,const char* src);
unsigned strlen(const char* str);

// printf.c
int fputc(int c,FILE* stream);
int fputs(const char* str,FILE* stream);
int printf(const char* format,...);
int fprintf(FILE* stream,const char* format,...);

// internal
void do_global_ctors();
void mini_crt_call_exit_routine();

// atexit
typedef void (*atexit_func_t)(void);
int atexit(atexit_func_t func);

#ifdef __cplusplus 
}
#endif

#endif // #define _MINI_CRT_H_